<template>
	<view class="p12 pt30">
		<view class="u-flex u-f-justify">
			
				<image src="../../../static/image/ic-bi.png" class="w16 h16 mr10"></image>
			邀请好友，得积分奖励
			<image src="../../../static/image/ic-bi.png" class="w16 h16 ml10"></image>
		</view>
		
		
		<view class="mt20 module-rule brs5 p16" style="background: rgba(25,41,28,0.05);">
			<view class="fz15">活动规则</view>
			<view class="fz12 c8 lh24 mt10">
				分享链接，好友成功注册账号即可获取相应的积分奖励；</br> 好友在小程序进行消费，根据消费金额可获取相应比例的积分奖励。 </br>积分奖励系统自动发放，无需手动领取，可在积分明细查看积分发放记录。
			</view>
		</view>
		<view class="mt18">
			<button class="inviteBtn fz14 u-font-bold" @tap="toCreated()">立即邀请</button>
		</view>
		<view class="u-flex mt32">
			
			<view class="u-f1 u-font-bold fz14" style="text-align: center;">
				<view class="fz24 mb4">2</view>
				<view>已邀请好友</view>
			</view>
			<view class="u-f1 u-font-bold fz14" style="text-align: center;">
				<view class="fz24 mb4">2</view>
				<view>已奖励积分</view>
			</view>
		</view>
		<view class="u-flex mt32 u-f-jsb fz12 c6 bm pb12">
			用户<span>奖励积分</span>
		</view>
		<view>
			<view class="u-flex pt16 u-f-jsb bm pb16" v-for="(item,index) in 10" :key="index">
				<view class="u-flex fz14">
					<u-avatar class="mr10" size="80" src=""></u-avatar>
					咕噜咕噜
				</view>
				<view class="fz14 u-font-bold" style="color: #70B52C;">150</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				curIndex: 0,
				recharge_attention: [],
				recharge_quota: []
			};
		},
		computed: {},
		onShow() {
			this.initData()

		},
		methods: {
			initData() {

				this.$api.rechargeIndex({}, res => {
					if (res.status == 200) {
						this.recharge_quota = res.data.recharge_quota;
						this.recharge_attention = res.data.recharge_attention;
					}
				})

			},


			toCreated() {
				let item = this.recharge_quota[this.curIndex]
				let post = {
					from: 'weixin',
					price: item.price,
					rechar_id: item.id,
					type: 0,
				}
				this.$api.rechargeAdd(post, res => {
					if (res.status == 200) {


						let info = res.data.result.jsConfig
						// 唤起微信支付。
						uni.requestPayment({
							provider: 'wxpay',
							timeStamp: info.timestamp,
							nonceStr: info.nonceStr,
							package: info.package,
							signType: info.signType,
							paySign: info.paySign,
							success: (res) => {

								uni.showToast({
									title: '支付成功',
									duration: 2000
								});
								setTimeout(() => {
									uni.navigateBack()
								}, 2000)
							},
							fail: (err) => {}
						});
					} else {

						this.$common.errorToShow(res.msg)
					}
				})
			},
			toPage(url) {
				uni.navigateTo({
					url
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	page{
		background: #fff;
	}
	.item {
		width:50%;
		min-width: 50%;
		max-width: 50%;
		padding: 0 10rpx;
		margin-bottom: 30rpx;

		.item-content {
			padding:50rpx 20rpx;
			background: #F6F6F6;
			border: 1px solid #ccc;
			border-radius: 15rpx;
			text-align: center;
		}

		&.on {
			.item-content {
				background: #EDF6FF;
				border: 1px solid #51A5FC;
				color: #51A5FC;
			}
		}

	}

	.inviteBtn {
		background: #70B52C;
		color: #fff;
		height:88rpx;
		line-height: 88rpx;
		border-radius: 10rpx;
	}
</style>